﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using UAXInversionesWeb.logicaNegocio;
using Telerik.Web.UI;

namespace UAXInversionesWeb.cliente
{
    public partial class ConsultarValores : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Proxy.isLogged())
            {
                Cotizaciones[] cotizaciones = Proxy.getCotizaciones();
                if (cotizaciones.Length > 0)
                {
                    mensaje.Text = "";

                    TableRow row;
                    TableCell cell, cell2, cell3, cell4;
                    double valor, diferencia;
                    string acronimo;

                    for (int i = 0; i < cotizaciones.Length; i++)
                    {
                        row = new TableRow();
                        if (i % 2 != 0)
                        {
                            row.BackColor = System.Drawing.Color.FromArgb(240, 244, 247);
                        }
                        acronimo = cotizaciones[i].getAcronimo();
                        valor = cotizaciones[i].getValorAccion();
                        diferencia = cotizaciones[i].getDiferenciaBase();

                        cell = new TableCell();
                        cell.HorizontalAlign = HorizontalAlign.Left;
                        cell.Text = Proxy.getNombreEmpresa(acronimo);
                        row.Cells.Add(cell);

                        cell2 = new TableCell();
                        cell2.HorizontalAlign = HorizontalAlign.Center;
                        cell2.Text = acronimo;
                        row.Cells.Add(cell2);

                        cell3 = new TableCell();
                        cell3.HorizontalAlign = HorizontalAlign.Right;
                        cell3.Text = valor.ToString("N") + " €";
                        row.Cells.Add(cell3);

                        cell4 = new TableCell();
                        cell4.HorizontalAlign = HorizontalAlign.Right;
                        Image img = new Image();
                        Label lab = new Label();
                        img.Width = 18;
                        img.Height = 20;
                        if (diferencia > 0)
                        {
                            lab.ForeColor = System.Drawing.Color.Green;
                            lab.Text = "+" + diferencia.ToString("N") + " € ";
                            img.ImageUrl = "../images/arrow_green.gif";

                        }
                        else if (diferencia == 0)
                        {
                            lab.ForeColor = System.Drawing.Color.Blue;
                            lab.Text = "0,00 € ";
                            img.ImageUrl = "../images/arrow_nochange.gif";
                        }
                        else
                        {
                            lab.ForeColor = System.Drawing.Color.Red;
                            lab.Text = diferencia.ToString("N") + " € ";
                            img.ImageUrl = "../images/arrow_red.gif";
                        }
                        cell4.Controls.Add(lab);
                        cell4.Controls.Add(img);

                        row.Cells.Add(cell4);

                        Table1.Rows.Add(row);
                    }
                }
                else
                {
                    mensaje.Text = "No hay cotizaciones actualmente.";
                }
            }
        }
    }
}
